package ttot.transitions.api

import org.openqa.selenium.{By, WebDriver}
import org.openqa.selenium.firefox.FirefoxDriver

class Concrete {

  @transition(
    name = "Start",
    adds = Array("session")
  )
  def createSession() = Map(
    "session" -> new FirefoxDriver(),
    "username" -> "randomgoogleuser@gmail.com",
    "password" -> "randomgooglepassword")

  @transition(
    name = "Stop",
    requires = Array("session"),
    removes = Array("session")
  )
  def destroySession(session: WebDriver) {
    session.quit()
  }

  @transition(
    name = "Open Login Page",
    requires = Array("session"),
    adds = Array("logInPage")
  )
  def openLoginPage(@k("session") driver: WebDriver) {
    driver.get("http://gmail.com/")
  }

  @transition(
    name = "Standard Login",
    requires = Array("username", "password", "session"),
    adds = Array("loggedIn"),
    removes = Array("logInPage")
  )
  def login(username: String, password: String, session: WebDriver) {
    session.findElement(By.id("Email")).sendKeys(username)
    session.findElement(By.id("Passwd")).sendKeys(password)
    session.findElement(By.id("signIn")).click()
    ("loggedIn" -> true)
  }

}
